
/**
 * @name NetCDFInterrogator
 *
 * @version 0.1.504 Alpha, MASS Wind Gradient 1, 4th commit
 * @date 10/4/2013
 * @author Niko Simonson
 * @author Brett Yasutake
 */
import java.io.IOException;
import java.util.AbstractMap.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import ucar.ma2.DataType;
import ucar.nc2.Dimension;
import ucar.nc2.Attribute;
import ucar.nc2.NetcdfFileWriteable;
import ucar.unidata.util.Parameter;

/**
 * @name Provenance
 *
 */
public class ProvenanceAdapter {

    // CONSTANTS
    public static final int DOUBLE = 0;
    public static final int STRING = 1;
    // Variables
    private int type;                       // every variable must be the same type
    private static String name;
    SimpleEntry<String, Integer[]>[] vars;  // name of variables, ranges of variable
    private static NetcdfFileWriteable currentFile;

    /**
     * @name ProvenanceAdapter
     * @param fileName
     */
    public ProvenanceAdapter(String fileName) {
        name = fileName;
    }

    /**
     * @name create
     * @param args
     */
    public void create(SimpleEntry<String, String>[] args) {
        try {
            currentFile = NetcdfFileWriteable.createNew(name);
            for (int i = 0; i < args.length; ++i) {
                currentFile.addGlobalAttribute(args[i].getKey(), args[i].getValue());
            }
            currentFile.create();
            currentFile.close();

        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    /**
     * @name getType
     * @return
     */
    private DataType getType() {
        switch (type) {
            case DOUBLE:
                return DataType.DOUBLE;
            case STRING:
                return DataType.STRING;
            default:
                return DataType.DOUBLE;
        }
    }

    /**
     * @name logProvenance
     */
    public static void logProvenance() {
        try {
            currentFile = NetcdfFileWriteable.openExisting(name);
            currentFile.close();
        } catch (IOException ex) {
            Logger.getLogger(ProvenanceAdapter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
